//
//  B_DetailTopicVC.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/8/12.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "B_TopicDetailVC.h"
#import "B_RightTopAlertView.h"
#import "B_ThreeButton.h"
#import "B_TopicDetailBasicModel.h"
#import "B_TopicDetailHeaderView.h"
#import "B_TopicDetailContentTVC.h"
#import "B_TopicDetailFooterView.h"
#import "B_TopicDetailHeaderTwo.h"
#import "B_CommentListVC.h"
#import "B_TopicListTVC.h"
#import "B_CommentListModel.h"
#import "B_CommentListHeaderView.h"
#import "B_UserMainPageVC.h"
#import "B_CommentListMoreTVC.h"
#import "B_CommentListTVC.h"
#import "B_TopicDetailFooterViewTwo.h"
#import "B_TopicDetailGoodsTVC.h"
#import "B_ReportListVC.h"
#import "B_GoodsDetailVC.h"


@interface B_TopicDetailVC ()

@property (nonatomic, strong) BaseView * mainView;

@property (nonatomic, strong) B_ThreeButton * footerView;

@property (nonatomic, strong) B_TopicDetailBasicModel * topicDetailModel;
/// 评论的数组
@property (nonatomic, strong) NSMutableArray * commentArray;
/// 商品的数组
@property (nonatomic, strong) NSMutableArray * goodsArray;

@end

@implementation B_TopicDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigation];
    self.view = self.mainView;
    _commentArray = [NSMutableArray array];
    _goodsArray = [NSMutableArray array];
    [_mainView addSubview:self.footerView];
    CGFloat bottom = SCREEN_HEIGHT > 800 ? (49 + 24) : 49;
    [self.footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
        make.height.equalTo(@(bottom));
    }];
    
    [_mainView setTableViewFrameWithTop:-getNavHeight() left:0 right:0 bottom:-bottom];
    [self getData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setNavigationBarBackgroundWithImage:[UIImage getImageWithColor:[UIColor clearColor] alp:0]];
    [self setNavigationBarShadowImge:[UIImage getImageWithColor:[UIColor clearColor] alp:0]];
}

- (void) setNavigation {
    WeakSelf(weSelf, self);
    [self setRightImageBarButtonItemWithFrame:CGRectZero image:@"B_topic_details_more" selectImage:@"" ishidden:YES action:^(GUIButton *button) {
        //TODO:执行弹窗
        B_RightTopAlertView * alertView = [B_RightTopAlertView initB_RightTopAlertView];
        [alertView show];
        alertView.dataArray = @[@{@"title" :@"分享", @"image" : @"B_topic_details_bounced_share"},@{@"title" : @"举报", @"image" : @"B_topic_details_bounced_report"}];
        alertView.selectIndex = ^(NSIndexPath *indexPath) {
            if (indexPath.row == 0) {
                //TODO: 执行分享
                HXLog(@"执行分享");
            } else if (indexPath.row == 1) {
                //TODO: 执行举报
                HXLog(@"执行举报");
                B_ReportListVC * report = [[B_ReportListVC alloc] init];
                report.B_userID = weSelf.topicDetailModel.userId;
                report.type = B_ReportListVCTypeTopic;
                report.topicId = weSelf.topicId;
                [weSelf pushNextViewController:report];
            }
        };
        
    }];
}

- (BaseView *)mainView {
    if (!_mainView) {
        WeakSelf(weSelf, self);
        _mainView = [[BaseView alloc] init];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_TopicDetailContentTVC" bundle:nil] forCellReuseIdentifier:@"B_TopicDetailContentTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_TopicListTVC" bundle:nil] forCellReuseIdentifier:@"B_TopicListTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_CommentListMoreTVC" bundle:nil] forCellReuseIdentifier:@"B_CommentListMoreTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_CommentListTVC" bundle:nil] forCellReuseIdentifier:@"B_CommentListTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_TopicDetailGoodsTVC" bundle:nil] forCellReuseIdentifier:@"B_TopicDetailGoodsTVC"];
        //TODO:section
        _mainView.numberOfSectionsBlock = ^NSInteger(UITableView *tableView) {
            if (weSelf.commentArray.count > 2) {
                return 6;
            } 
            return 4 + weSelf.commentArray.count;
        };
        //TODO:row
        _mainView.numberOfRowsBlock = ^NSInteger(UITableView *tableView, NSInteger section) {
            if (section == 1) {
                return 0;
            }
            
            if (weSelf.commentArray.count > 2) {
                if (section == 2 || section == 3) {
                    B_CommentListModel * commentModel = weSelf.commentArray[section - 2];
                    if ([commentModel.twoCommentCount integerValue] > 4) {
                        return 5;
                    } else {
                        return [commentModel.twoCommentCount integerValue];
                    }
                } else if (section == 4) {
                    if (weSelf.topicDetailModel.associationGoodsBackListArray.count > 0) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            } else if (weSelf.commentArray.count == 1) {
                if (section == 2) {
                    B_CommentListModel * commentModel = weSelf.commentArray[section - 2];
                    if ([commentModel.twoCommentCount integerValue] > 4) {
                        return 5;
                    } else {
                        return [commentModel.twoCommentCount integerValue];
                    }
                } else if (section == 3) {
                    if (weSelf.topicDetailModel.associationGoodsBackListArray.count > 0) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            } else if (weSelf.commentArray.count == 0) {
                if (section == 2) {
                    if (weSelf.topicDetailModel.associationGoodsBackListArray.count > 0) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            }
            
            
            
            return 1;
        };
        //TODO:组头
        _mainView.viewForHeaderBlock = ^UIView *(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                B_TopicDetailHeaderView * header = [B_TopicDetailHeaderView initB_TopicDetailHeaderView];
                [header.B_userImageView sd_setImageWithURL:[NSURL URLWithString:weSelf.topicDetailModel.portrait]];
                header.B_userName.text = weSelf.topicDetailModel.nickName;
                [header.B_userTypeImageView setUsetType:weSelf.topicDetailModel.userType];
                header.B_titleLabel.text = weSelf.topicDetailModel.title;
                if ([weSelf.topicDetailModel.is_follow isEqualToString:@"1"]) {
                    header.B_attentionButton.selected = YES;
                } else {
                    header.B_attentionButton.selected = NO;
                }
                NSMutableArray * array = [NSMutableArray array];
                [array removeAllObjects];
                for (NSDictionary * dictionary in weSelf.topicDetailModel.topicPictureList) {
                    [array addObject:dictionary[@"picture"]];
                }
                header.array = array;
                header.topicHeaderAction = ^(NSInteger index, BOOL isAttention) {
                    if (isAttention) {      //TODO:关注
                        [weSelf attention];
                    } else {                // 查看大图
                        
                    }
                };
                return header;
            } else if (section == 1) {
                B_TopicDetailHeaderTwo * header = [B_TopicDetailHeaderTwo initB_TopicDetailHeaderTwo];
                header.B_titleLabel.text = @"全部评论";
                header.B_button.hidden = NO;
                [header.B_button setTitle:[NSString stringWithFormat:@"共%@条评论", safeValue1(weSelf.topicDetailModel.topicCommentCount)] forState:UIControlStateNormal];
                [header.B_button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:10];
                header.topicHeaderAction = ^{
                    //TODO:查看全部评论
                    B_CommentListVC * vc = [[B_CommentListVC alloc] init];
                    vc.topicId = weSelf.topicId;
                    [weSelf pushNextViewController:vc];
                };
                return header;
            } else {
                /// 展示评论   最多两条
                if (weSelf.commentArray.count > 2) {
                    if (section == 2 || section == 3) {
                        B_CommentListModel * commentModel = weSelf.commentArray[section - 2];
                        return [weSelf commentHeader:commentModel];
                    }
                } else if (weSelf.commentArray.count == 1) {
                    if (section == 2) {
                        B_CommentListModel * commentModel = weSelf.commentArray[section - 2];
                        return [weSelf commentHeader:commentModel];
                    }
                }
                B_TopicDetailHeaderTwo * header = [B_TopicDetailHeaderTwo initB_TopicDetailHeaderTwo];
                if (weSelf.commentArray.count > 2) {
                    if (section == 4) {
                        header.B_titleLabel.text = @"关联商品";
                    } else if (section == 5) {
                        header.B_titleLabel.text = @"猜你喜欢";
                    }
                } else {
                    if (section == 2 + weSelf.commentArray.count) {
                        header.B_titleLabel.text = @"关联商品";
                    } else {
                        header.B_titleLabel.text = @"猜你喜欢";
                    }
                }
                
                header.B_button.hidden = YES;
                
                return header;
            }
            return nil;
        };
        
        _mainView.cellForRowBlock = ^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
            if (indexPath.section == 0) {
                B_TopicDetailContentTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_TopicDetailContentTVC" forIndexPath:indexPath];
                cell.B_contentLabel.text = weSelf.topicDetailModel.content;
                return cell;
            } else  {
                if (weSelf.commentArray.count > 2) {
                    if (indexPath.section == 2 || indexPath.section == 3) {
                        B_CommentListModel * tmodel = weSelf.commentArray[indexPath.section - 2];
                        return [weSelf setComment:tmodel indexPath:indexPath talbeview:tableView];
                    } else if (weSelf.commentArray.count == 1) {
                        if (indexPath.section == 2) {
                            B_CommentListModel * tmodel = weSelf.commentArray[indexPath.section - 2];
                            return [weSelf setComment:tmodel indexPath:indexPath talbeview:tableView];
                        }
                    }
                }
                
                if (weSelf.commentArray.count > 2) {
                    if (indexPath.section == 4) {       // TODO:关联商品
                        B_TopicDetailGoodsTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_TopicDetailGoodsTVC" forIndexPath:indexPath];
                        cell.goodsArray = weSelf.topicDetailModel.associationGoodsBackListArray;
                        cell.collectionTapAction = ^(NSIndexPath *indexPath) {
                            B_GoodsDetailVC * vc = [[B_GoodsDetailVC alloc] init];
                            B_TopicAboutGoodsModel * model = weSelf.topicDetailModel.associationGoodsBackListArray[indexPath.row];
                            vc.B_GoodsId = model.id;
                            [weSelf pushNextViewController:vc];
                        };
                        return cell;
                        
                    } else if (indexPath.section == 5) {
                        B_TopicListTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_TopicListTVC" forIndexPath:indexPath];
                        
                        return cell;
                    }
                } else {
                    if (indexPath.section == 2 + weSelf.commentArray.count) {   // TODO:商品
                        B_TopicDetailGoodsTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_TopicDetailGoodsTVC" forIndexPath:indexPath];
                        cell.goodsArray = weSelf.topicDetailModel.associationGoodsBackListArray;
                        cell.collectionTapAction = ^(NSIndexPath *indexPath) {
                            B_GoodsDetailVC * vc = [[B_GoodsDetailVC alloc] init];
                            B_TopicAboutGoodsModel * model = weSelf.topicDetailModel.associationGoodsBackListArray[indexPath.row];
                            vc.B_GoodsId = model.id;
                            [weSelf pushNextViewController:vc];
                        };
                        return cell;
                    } else {
                        B_TopicListTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_TopicListTVC" forIndexPath:indexPath];
                        
                        return cell;
                    }
                }
                
            }
            UITableViewCell * cell = [[UITableViewCell alloc] init];
            
            return cell;
        };
        
        _mainView.viewForFooterBlock = ^UIView *(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                B_TopicDetailFooterView * footer = [B_TopicDetailFooterView initB_TopicDetailFooterView];
                footer.B_timeLabel.text = [NSObject getTimeTo:weSelf.topicDetailModel.createTime];
                footer.B_pageLabel.text = [NSString stringWithFormat:@"%@次浏览", safeValue1(weSelf.topicDetailModel.pageView)];
                return footer;
            }
            if (weSelf.commentArray.count > 2) {
                if (section == 4) {         // TODO:添加查看更多按钮
                    B_TopicDetailFooterViewTwo * footer = [B_TopicDetailFooterViewTwo initB_TopicDetailFooterViewTwo];
                    footer.topicFooterAction = ^{
                        //TODO:查看全部评论
                        B_CommentListVC * vc = [[B_CommentListVC alloc] init];
                        vc.topicId = weSelf.topicId;
                        [weSelf pushNextViewController:vc];
                    };
                    return footer;
                }
            }
            UIView * view = [[UIView alloc] init];
            view.backgroundColor = [UIColor color_main_background_color];
            return view;
        };
        
        
    }
    return _mainView;
}

- (B_ThreeButton *)footerView {
    if (!_footerView) {
        WeakSelf(weSelf, self);
        _footerView = [B_ThreeButton initB_ThreeButton];
        _footerView.buttonAction = ^(NSInteger index) {
            if (index == 1) {       // TODO:点赞
                [weSelf likeAction];
                
            } else if (index == 2) {    // TODO:评论
                
            } else if (index == 3) {    // TODO:收藏
                [weSelf collection];
            }
        };
        
        
    }
    return _footerView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 TODO:获取服务端数据
 */
- (void) getData {
    WeakSelf(weSelf, self);
    [NetworkingManager getNetworkRequestWithUrlString:[NSString stringWithFormat:@"/yearnfor/inter/topic/selectTopicInfo/%@/%@", self.topicId, getUserId()] parameters:nil isCache:NO succeed:^(id data) {
        if ([data[@"code"] isEqualToString:@"20010"]) {
            weSelf.topicDetailModel = [B_TopicDetailBasicModel mj_objectWithKeyValues:data[@"values"]];
            weSelf.topicDetailModel.associationGoodsBackListArray = [NSMutableArray array];
            for (NSDictionary * dic in weSelf.topicDetailModel.associationGoodsBackList) {
                B_TopicAboutGoodsModel * model = [B_TopicAboutGoodsModel mj_objectWithKeyValues:dic];
                [weSelf.topicDetailModel.associationGoodsBackListArray addObject:model];
            }
            [weSelf.footerView.B_leftButton setTitle:[NSString stringWithFormat:@"赞%@", safeValue1(self.topicDetailModel.likeCount)] forState:UIControlStateNormal];
            [weSelf.footerView.B_middleButton setTitle:[NSString stringWithFormat:@"评论%@", safeValue1(self.topicDetailModel.topicCommentCount)] forState:UIControlStateNormal];
            [weSelf.footerView.B_rightButton setTitle:[NSString stringWithFormat:@"收藏%@", safeValue1(self.topicDetailModel.topicCollectCount)] forState:UIControlStateNormal];
            [weSelf.mainView.tableView reloadData];
        } else {
            [KeyWindow makeToast:data[@"message"]];
        }
    } fail:^(NSError *error) {
        [KeyWindow makeToast:@"服务器异常"];
    }];
    /// 获取评论数据
    [NetworkingManager getNetworkRequestWithUrlString:[NSString stringWithFormat:@"/yearnfor/inter/topic/selectTopicCommentList/%@/%@/1/10", self.topicId, getUserId()] parameters:nil isCache:NO succeed:^(id data) {
        if ([data[@"code"] isEqualToString:@"20010"]) {
            [weSelf.commentArray removeAllObjects];
            for (NSDictionary * dictionary in data[@"values"]) {
                B_CommentListModel * model = [B_CommentListModel mj_objectWithKeyValues:dictionary];
                model.topicTwoCommentListArray = [NSMutableArray array];
                for (NSDictionary * dic in model.topicTwoCommentList) {
                    B_TopicTwoCommentListModel * twoModel = [B_TopicTwoCommentListModel mj_objectWithKeyValues:dic];
                    [model.topicTwoCommentListArray addObject:twoModel];
                }
                [weSelf.commentArray addObject:model];
            }
            [weSelf.mainView.tableView reloadData];
        } else {
            [KeyWindow makeToast:data[@"message"]];
        }
    } fail:^(NSError *error) {
        [KeyWindow makeToast:@"服务员异常"];
    }];
}


/**
 TODO:关注
 */
- (void) attention {
    
}

/**
 TODO:点赞
 */
- (void) likeAction {
    WeakSelf(weSelf, self);
    [NetworkingManager getNetworkRequestWithUrlString:[NSString stringWithFormat:@"/yearnfor/inter/topiclike/UserAddDelTopicLike/%@/%@", self.topicId, getUserId()] parameters:nil isCache:NO succeed:^(id data) {
        if ([data[@"code"] isEqualToString:@"20006"]) {
            [KeyWindow makeToast:@"操作成功"];
            [weSelf getData];
        } else {
            [KeyWindow makeToast:data[@"message"]];
        }
    } fail:^(NSError *error) {
        [KeyWindow makeToast:@"服务器异常"];
    }];
}

/**
 TODO:评论的点赞

 @param model 模型
 */
- (void) likeAction:(B_CommentListModel *) model {
    ///yearnfor/inter/topicCommentLike/addCommentLike/1/1
    
    WeakSelf(weSelf, self);
    [NetworkingManager getNetworkRequestWithUrlString:[NSString stringWithFormat:@"yearnfor/inter/topicCommentLike/addCommentLike/%@/%@", model.id, getUserId()] parameters:nil isCache:NO succeed:^(id data) {
        if ([data[@"code"] isEqualToString:@"20005"]) {
            [KeyWindow makeToast:@"操作成功"];
            [weSelf getData];
        } else {
            [KeyWindow makeToast:data[@"message"]];
        }
    } fail:^(NSError *error) {
        [KeyWindow makeToast:@"服务器异常"];
    }];
}

/**
 TODO:收藏
 */
- (void) collection {
    WeakSelf(weSelf, self);
    [NetworkingManager getNetworkRequestWithUrlString:[NSString stringWithFormat:@"/yearnfor/inter/topiccollect/addAndDelTopicCollect/%@/%@", self.topicId, getUserId()] parameters:nil isCache:NO succeed:^(id data) {
        if ([data[@"code"] isEqualToString:@"20005"]) {
            [KeyWindow makeToast:@"操作成功"];
            [weSelf getData];
        } else {
            [KeyWindow makeToast:data[@"message"]];
        }
    } fail:^(NSError *error) {
        [KeyWindow makeToast:@"服务器异常"];
    }];
}

- (BaseTableViewCell *) setComment:(B_CommentListModel *) tmodel indexPath:(NSIndexPath *) indexPath talbeview:(UITableView *) tableView{
        B_TopicTwoCommentListModel * model;
        if (tmodel.showAll) {
            if (indexPath.row == [tmodel.twoCommentCount integerValue]) {
                /// 查看更多按钮
                B_CommentListMoreTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_CommentListMoreTVC" forIndexPath:indexPath];
                return cell;
            } else {
                model = tmodel.topicTwoCommentListArray[indexPath.row];
            }
        } else {
            if ([tmodel.twoCommentCount integerValue] > 4) {
                if (indexPath.row == 4) {
                    /// 查看更多按钮
                    B_CommentListMoreTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_CommentListMoreTVC" forIndexPath:indexPath];
                    return cell;
                    
                } else {
                    model = tmodel.topicTwoCommentListArray[indexPath.row];
                }
            } else {
                model = tmodel.topicTwoCommentListArray[indexPath.row];
            }
        }
        ///
        B_CommentListTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_CommentListTVC" forIndexPath:indexPath];
        NSMutableAttributedString * text = [[NSMutableAttributedString alloc] init];
        {
            
            NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:safeValue3(model.userNickName)];
            string.yy_font = [UIFont systemFontOfSize:12];
            string.yy_lineHeightMultiple = 1.15;
            [string yy_setTextHighlightRange:string.yy_rangeOfAll
                                       color:[UIColor color_text_deep_gray]
                             backgroundColor:[UIColor colorWithWhite:0.000 alpha:0.20]
                                   tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
                                       NSLog(@"点击事件发生了");
                                       
                                       B_UserMainPageVC * vc = [[B_UserMainPageVC alloc] init];
                                       vc.B_userId = model.topicCommentUserId;
                                       [self pushNextViewController:vc];
                                       
                                   }];
            [text appendAttributedString:string];
            
            if ([model.topicCommentByUserId isEqualToString:getUserId()]) {
                
                NSMutableAttributedString * string1 = [[NSMutableAttributedString alloc] initWithString:@":"];
                string1.yy_font = [UIFont systemFontOfSize:12];
                string1.yy_color = [UIColor color_text_white];
                [text appendAttributedString:string1];
                
                NSMutableAttributedString * string2 = [[NSMutableAttributedString alloc] initWithString:model.content];
                string2.yy_font = [UIFont systemFontOfSize:12];
                string2.yy_lineHeightMultiple = 1.15;
                [string2 yy_setTextHighlightRange:string2.yy_rangeOfAll
                                            color:[UIColor color_text_light_gray]
                                  backgroundColor:[UIColor colorWithWhite:0.000 alpha:0.20]
                                        tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
                                            //TODO:评论内容的点击事件
                                        }];
                [text appendAttributedString:string2];
            } else {
                
                NSMutableAttributedString * string4 = [[NSMutableAttributedString alloc] initWithString:@" 回复 "];
                string4.yy_font = [UIFont systemFontOfSize:12];
                string4.yy_color = [UIColor color_text_white];
                [text appendAttributedString:string4];
                
                
                NSMutableAttributedString * string1 = [[NSMutableAttributedString alloc] initWithString:safeValue3(model.byUserNickName)];
                string1.yy_font = [UIFont systemFontOfSize:12];
                string1.yy_lineHeightMultiple = 1.15;
                [string1 yy_setTextHighlightRange:string1.yy_rangeOfAll
                                            color:[UIColor color_text_deep_gray]
                                  backgroundColor:[UIColor colorWithWhite:0.000 alpha:0.20]
                                        tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
                                            //TODO:被评论人点击事件
                                            B_UserMainPageVC * vc = [[B_UserMainPageVC alloc] init];
                                            vc.B_userId = model.topicCommentByUserId;
                                            [self pushNextViewController:vc];
                                        }];
                [text appendAttributedString:string1];
                
                
                NSMutableAttributedString * string3 = [[NSMutableAttributedString alloc] initWithString:@": "];
                string3.yy_font = [UIFont systemFontOfSize:12];
                string3.yy_color = [UIColor color_text_white];
                [text appendAttributedString:string3];
                
                NSMutableAttributedString * string2 = [[NSMutableAttributedString alloc] initWithString:model.content];
                string2.yy_font = [UIFont systemFontOfSize:12];
                string2.yy_lineHeightMultiple = 1.15;
                [string2 yy_setTextHighlightRange:string2.yy_rangeOfAll
                                            color:[UIColor color_text_light_gray]
                                  backgroundColor:[UIColor colorWithWhite:0.000 alpha:0.20]
                                        tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
                                            //TODO:评论内容的点击事件
                                            
                                        }];
                [text appendAttributedString:string2];
                
            }
        }
        cell.B_commentLabel.attributedText = text;
        cell.B_commentLabel.numberOfLines = 0;
        
        cell.B_placeLabel.attributedText = text;
        return cell;
    
}

/**
 TODO:评论的组头

 @param commentModel 评论的模型
 @return 返回组头
 */
- (UIView *) commentHeader: (B_CommentListModel *) commentModel {
    WeakSelf(weSelf, self);
    B_CommentListHeaderView * header = [B_CommentListHeaderView initB_CommentListHeaderView];
    [header.B_userImageView sd_setImageWithURL:[NSURL URLWithString:commentModel.portrait]];
    header.B_userName.text = commentModel.nickName;
    if ([commentModel.is_like isEqualToString:@"1"]) {
        header.B_likeButton.selected = YES;
    } else {
        header.B_likeButton.selected = NO;
    }
    [header.B_likeButton setTitle:safeValue1(commentModel.likeCouont) forState:UIControlStateNormal];
    [header.B_userTypeImageView setUsetType:commentModel.userType];
    
    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:commentModel.content];
    string.yy_font = [UIFont systemFontOfSize:12];
    string.yy_lineHeightMultiple = 1.15;
    [string yy_setTextHighlightRange:string.yy_rangeOfAll
                               color:[UIColor color_text_light_gray]
                     backgroundColor:[UIColor colorWithWhite:0.000 alpha:0.20]
                           tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
                               
                               //TODO: 评论事件  一级评论
                           }];
    
    header.B_commentLabel.attributedText = string;
    header.B_commentLabel.numberOfLines = 0;
    header.B_placeLabel.text = commentModel.content;
    header.tapAction = ^{
        [weSelf likeAction:commentModel];
    };
    return header;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
